<template>
    <van-skeleton title :row="3" />
    <div>
        <h2>注册</h2>
        <p><van-image
  round
  style="width: 70px;height: 70px;"
  width="10rem"
  height="10rem"
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>
<span>产品slogo</span>
</p>
<van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="username"
      label="用户名"
      placeholder="用户名"
      :rules="[{ pattern, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="password"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { showSuccessToast, showFailToast } from 'vant';
import router from '@/router';
import { registerApi } from '@/api/api';
let registerApiData=ref([])
const username = ref('');
const password = ref('');
const pattern=/^1[3-9]\d{9}$/
    const onSubmit = () => {
        if(password.value.length<9){
            registerApi(username.value,password.value).then(res=>{
        if(res.data.code==0){
            registerApiData.value=res.data.message
            showSuccessToast('注册成功');
            router.push('/login')
        }else{
            showFailToast('注册失败');
        }
      })
        }else{
            showFailToast('密码不能超过8位数');
        }
    };
</script>

<style scoped>
h2{
    text-align: center;
}
p{
    height: 70px;
    text-align: center;
}
</style>